package ch.exm.storm.functional;

import java.lang.reflect.Method;
import java.util.Collection;

import ch.exm.storm.functional.functions.Aggregator;

public class ProxyAggregator<T, A> extends ProxyIterator<T> {

	private Aggregator<A> aggregator;
	
	ProxyAggregator(Collection<T> proxiedCollection, Aggregator<A> aggregator) {
		super(proxiedCollection);
		this.aggregator = aggregator;
	}
	
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		return CollectionUtil.aggregate(collectValues(method, args), aggregator);
	}
}
